package com.zone.domain.strategy.service.rule.tree.factory;

import com.zone.domain.strategy.model.valobj.RuleActionEnum;
import com.zone.domain.strategy.model.valobj.RuleTreeVO;
import com.zone.domain.strategy.service.rule.tree.ILogicTreeNode;
import com.zone.domain.strategy.service.rule.tree.factory.engine.IDecisionTreeEngine;
import com.zone.domain.strategy.service.rule.tree.factory.engine.impl.DefaultDecisionTreeEngine;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author: zongzi
 * @description: 树节点工厂，提供获取树节点逻辑
 * @date: 2024/6/11
 */
@Slf4j
@Component
public class DefaultTreeNodeFactory {

    // 树节点执行器
    private final Map<String, ILogicTreeNode> treeNodeMap;

    public DefaultTreeNodeFactory(Map<String, ILogicTreeNode> treeNodeMap) {
        this.treeNodeMap = treeNodeMap;
    }

    /**
     * 获取规则树执行引擎
     *
     * @param ruleTreeVO 规则树
     * @return 规则树执行引擎
     */
    public IDecisionTreeEngine openLogic(RuleTreeVO ruleTreeVO) {
        return new DefaultDecisionTreeEngine(ruleTreeVO, treeNodeMap);
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class StrategyAwardVO {
        /** 奖品id */
        private Integer awardId;

        /** 奖品规则配置业务值 */
        private String awardRuleValue;
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class TreeNodeActionEntity {
        /** 树节点执行/放行请求 */
        private RuleActionEnum ruleAction;

        /** 策略奖品信息 */
        private StrategyAwardVO strategyAward;
    }

}
